import java.util.ArrayList;
import java.util.Scanner;

public class PressMangement {
    Presses press;
    Scanner scanner = new Scanner(System.in);
    ArrayList<Presses> presses = new ArrayList<Presses>();
    public PressMangement(){
        presses.add(new Presses("深圳出版社","深圳","21654"));
        presses.add(new Presses("上海出版社","上海","54512"));
        presses.add(new Presses("龙岩出版社","龙岩","48421"));
        presses.add(new Presses("北京出版社","北京","87421"));
    }
    public void add(){
        boolean s = true;
        System.out.println("请输入出版社名字");
        String name = scanner.next();
        System.out.println("请输入出版社地址");
        String address = scanner.next();
        System.out.println("请输入出版社电话号码");
        String phone = scanner.next();
        for(int i = 0;i<presses.size();i++){
            if(presses.get(i).name.equals(name)){
                System.out.println("出版社已存在");
                s = false;
            }if(i == presses.size()-1 && s == true){
                presses.add(new Presses(name,address,phone));
                System.out.println("添加成功");
                break;
            }
        }
    }
    public void delect() {
        Boolean s = false;
        boolean t = false;
        System.out.println("请输入要删除的出版社名字");
        String name = scanner.next();
        BookMangement bm = new BookMangement();
        for(int b = 0;b < bm.book.size();b++) {
            if (bm.book.get(b).press.equals(name)) {
                System.out.println("该出版社有相关图书信息存在！不可以删除！如果要删除请先删除所有相关图书信息！！！");
                t = true;
            }
            if (b == bm.book.size() - 1 && t == false) {

                for (int i = 0; i < presses.size(); i++) {

                if (presses.get(i).name.equals(name)) {
                    presses.remove(i);
                    System.out.println("删除成功");
                    s = true;
                }
                if (i == presses.size() - 1 && s == false) {
                    System.out.println("该出版社不存在");
                    break;
                }
                }
            }
        }
    }
    public void update() {
        boolean s = false;
        System.out.println("请输入想要更新的出版社名称");
        String name = scanner.next();
        for (int i = 0; i < presses.size(); i++) {
            if (presses.get(i).name.equals(name)) {
                System.out.println("请输入修改后的出版社名称");
                String newname = scanner.next();
                System.out.println("请输入修改后的出版社地址");
                String newaddress = scanner.next();
                System.out.println("请输入修改后的出版社联系电话");
                String newphone = scanner.next();
                ;
                presses.set(i, new Presses(newname, newaddress, newphone));
                System.out.println("更新成功");
                s = true;
            }
            if (i == presses.size() - 1 && s == false) {
                System.out.println("您输入的出版社名称不存在，请重新输入，或选择返回上一级（1.是  2.否）");
                int yes = scanner.nextInt();
                if (yes == 1) {
                    break;
                }
            }
        }
    }
    public void select(){
        boolean s = false;
        System.out.println("请输入你想要查询的出版社名称关键词");
        String name = scanner.next();
        for(int i = 0;i < presses.size();i++){
            if(presses.get(i).name.contains(name)){
                System.out.println(presses.get(i));
                s = true;
            }
            if(i == presses.size()-1 && s == false){
                System.out.println("出版社名称不存在");
                break;
            }
        }
    }
    public void allselect(){
        for(int i = 0;i < presses.size();i++) {
            System.out.println(presses.get(i));
        }
    }
}